var SubGameLayer = cc.Layer.extendEX({
    /**
     * 初始化游戏场景
     * @param data
     * @param roomDataType
     */
    initGameLayer: function (data, roomDataType) {
        var isReplay = (roomDataType == ROOM_DATA_TYPE.REPLAY);
        var isReconnect = (roomDataType == ROOM_DATA_TYPE.RECONNECT);
        var reconnectData = this._getRoomData(data, roomDataType);
        var roomLayer = null;
        switch (gameData.mapId) {
            case app.map_id.ZHUANZHUAN:
            case app.map_id.CHANGSHA:
            case app.map_id.HONGZHONG:
            case app.map_id.YUEYANG:
            case app.map_id.CHENZHOU:
            case app.map_id.SHAOYANG:
            case app.map_id.YIYANG:
            case app.map_id.WD:
            case app.map_id.YIYANG_SUOGANGZI:
                roomLayer = new MaRoomHuNan(reconnectData, roomDataType);
                break;
        }
        if (!roomLayer) {
            showAlert('场景不存在');
        }
        window.maLayer = roomLayer;

        this._roomLayer = roomLayer;
        this.addChild(roomLayer);
        return roomLayer;
    },


    /**
     * 根据data和roomDataType转换出房间数据
     * @param data
     * @param roomDataType
     * @returns {*}
     * @private
     */
    _getRoomData: function (data, roomDataType) {
        gameData.wanfatype = 'java';
        mRoom.wanfatype = '';
        var curData = data;
        var tData = data;
        if (roomDataType == ROOM_DATA_TYPE.REPLAY && data['3002']) {//回放
            curData = data['3002']['data'];
            gameData.last3002 = data['3002'];
            gameData.isReplay = true;
            tData = data;
        }
        gameData.roomId = curData['room_id'];
        gameData.mapId = curData['map_id'];
        gameData.mapName = curData['map_name'];
        gameData.players = curData['players'];
        gameData.ownerUid = curData['owner_uid'] || curData['owner'];
        gameData.zhuangUid = curData['zhuang_uid'];
        gameData.wanfaDesp = curData['desp'];
        gameData.leftRound = curData['left_round'];
        if (gameData.leftRound == undefined) {
            gameData.leftRound = curData['total_round'] - 1;
        }
        gameData.diceData = curData['diceNum'];
        gameData.totalRound = curData['total_round'];
        gameData.anticheating = curData['anticheating'] || false;
        gameData.roomStatus = curData['room_status'] || 1;
        gameData.playerNum = curData['max_player_cnt'] || curData['players'].length;
        gameData.daikaiPlayer = curData['daikai_player'];
        gameData.shipin = curData['shipin'] || 0;
        gameData.last3002 = curData;
        gameData.curRound = curData['cur_round'];
        gameData.roomClubId = curData['club_id'];
        gameData.AutoReady = true;
        gameData.distance = curData['distance'] || 100;
        gameData.options = curData['options'];
        if (curData['options']) {
            if (curData['options']['club_id']) {
                gameData.roomClubId = curData['options']['club_id'];
            }
            if (curData['options']['robot']) {
                gameData.robot = curData['options']['robot'];
            }
            if (curData['options']['checkDistance']) {
                gameData.anticheating = curData['options']['checkDistance'];
            }
            if (curData['options']['AutoReady'] != undefined && curData['options']['AutoReady'] != null) {
                gameData.AutoReady = curData['AutoReady'];
            }
            if (curData['options']['distance']) {
                gameData.distance = curData['options']['distance'];
            }
            if (curData['options']['yunxujiaru']) {
                gameData.yunxujiaru = curData['options']['yunxujiaru'];
            }
            if(curData['options']['jushu'] && !gameData.totalRound){
                gameData.totalRound = curData['options']['jushu'];
            }
        }
        return tData;
    },

});